package com.macy.mysok;

import android.app.Application;
import android.os.Environment;

import org.xutils.DbManager;
import org.xutils.x;

import java.io.File;

public class App extends Application {



    public DbManager db;

    @Override
    public void onCreate() {
        super.onCreate();
        try{
            x.Ext.init(this);

              DbManager.DaoConfig daoConfig = new DbManager.DaoConfig()
                    .setDbName("macy_btc.db")
                    // 不设置dbDir时, 默认存储在app的私有目录.
                    //.setDbDir(dbFile) // "sdcard"的写法并非最佳实践, 这里为了简单, 先这样写了.
                    .setDbVersion(1)
                    .setDbOpenListener(new DbManager.DbOpenListener() {
                        @Override
                        public void onDbOpened(DbManager db) {
                            // 开启WAL, 对写入加速提升巨大
                            db.getDatabase().enableWriteAheadLogging();
                        }
                    })
                    .setDbUpgradeListener(new DbManager.DbUpgradeListener() {
                        @Override
                        public void onUpgrade(DbManager db, int oldVersion, int newVersion) {

                        }
                    });

            db = x.getDb(daoConfig);
        }catch (Exception e){}

    }


    public String getSDPath(){
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(android.os.Environment.MEDIA_MOUNTED);//判断sd卡是否存在
        if(sdCardExist)
        {
            sdDir = Environment.getExternalStorageDirectory();//获取跟目录
        }
        return sdDir.toString();
    }
}
